# coding=utf-8
# !/usr/bin/python3
import json
import execjs
import requests

cookies = {
    'routeId': '.uc1',
    'Hm_lvt_489bd07e99fbfc5f12cbb4145adb0a9b': '1725532298',
    'HMACCOUNT': 'ED0735D1CE0FB96D',
    'MALLSSID': '4A69556445633150376C67697471516252514D4E4853565331395A4C413375576E6C6A5833694C5A3856782F5259544F617547764933614953374A37527A7138',
    'Hm_lpvt_489bd07e99fbfc5f12cbb4145adb0a9b': '1725532350',
}

headers = {
    'Accept': '*/*',
    'Accept-EncKey': '',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    # 'Cookie': 'routeId=.uc1; Hm_lvt_489bd07e99fbfc5f12cbb4145adb0a9b=1725532298; HMACCOUNT=ED0735D1CE0FB96D; MALLSSID=4A69556445633150376C67697471516252514D4E4853565331395A4C413375576E6C6A5833694C5A3856782F5259544F617547764933614953374A37527A7138; Hm_lpvt_489bd07e99fbfc5f12cbb4145adb0a9b=1725532350',
    'Origin': 'https://webapi.cninfo.com.cn',
    'Pragma': 'no-cache',
    'Referer': 'https://webapi.cninfo.com.cn/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}
with open('巨潮资讯.js', 'r', encoding='utf-8') as js_file:
    js_code = js_file.read()
js_compile = execjs.compile(js_code).call('getResCode')
headers['Accept-EncKey']=js_compile
data = {
    'tdate': '2024-08-02',
    'scode': '399001',
}

response = requests.post('https://webapi.cninfo.com.cn/api/sysapi/p_sysapi1015', cookies=cookies, headers=headers, data=data).json()
formatted_response = json.dumps(response, ensure_ascii=False, indent=4)  # 美化输出

print(formatted_response)